package com.prs.crm.domain.project;

import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;

import com.prs.crm.context.Constrains;
import com.prs.crm.domain.Attachment;
import com.prs.crm.domain.Currency;
import com.prs.crm.domain.District;
import com.prs.crm.domain.FlowEntity;

@Entity
@Table(name="prj_project")
public class Project extends  FlowEntity{

	private static final long serialVersionUID = 4493341401140560033L;
	
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	private String name;
	
	@ManyToOne
	private ProjectSource source;
	
	@ManyToOne
	private ProjectType type;
	
	
	
	@ManyToMany(fetch=FetchType.LAZY)
	@Cascade({org.hibernate.annotations.CascadeType.ALL,org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
	private Set<Attachment>  references;
	
	/**
	 * 项目预算
	 */
	private Double budget;
	
	@ManyToOne
	private ProjectStage stage;
	
	@ManyToOne
	private District district;
	
	@ManyToOne
	private Currency currency;
	
	private Integer status;
	
	/**
	 * 项目总结
	 */
	@Lob
	private String  summary;
	
	private Date startTime;
	
	private Date endTime;
	
	private Date realStartTime;
	
	private Date realEndTime;
	
	/**
	 * 冻结原因
	 */
	@Lob
	private String frostReason;
	
	@Lob
	private String remark; 



	public void setId(Integer id) {
		this.id = id;
	}

	public Integer getId() {
		return id;
	}

	public void setSource(ProjectSource source) {
		this.source = source;
	}

	public ProjectSource getSource() {
		return source;
	}

	public void setType(ProjectType type) {
		this.type = type;
	} 

	public ProjectType getType() {
		return type;
	}

	public void setBudget(Double budget) {
		this.budget = budget;
	}

	public Double getBudget() {
		return budget;
	}

	public void setStage(ProjectStage stage) {
		this.stage = stage;
	}

	public ProjectStage getStage() {
		return stage;
	}

	public void setDistrict(District district) {
		this.district = district;
	}

	public District getDistrict() {
		return district;
	}

	public void setCurrency(Currency currency) {
		this.currency = currency;
	}

	public Currency getCurrency() {
		return currency;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getRemark() {
		return remark;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public Integer getStatus() {
		return status;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public String getSummary() {
		return summary;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setRealStartTime(Date realStartTime) {
		this.realStartTime = realStartTime;
	}

	public Date getRealStartTime() {
		return realStartTime;
	}

	public void setRealEndTime(Date realEndTime) {
		this.realEndTime = realEndTime;
	}

	public Date getRealEndTime() {
		return realEndTime;
	}

	public void setReferences(Set<Attachment> references) {
		this.references = references;
	}

	public Set<Attachment> getReferences() {
		return references;
	}
	
	public void addAllReference(Collection<Attachment> attachs)
	{
		if (references==null)
			references = new HashSet<Attachment>();
		references.addAll(attachs);
	}
	
	/**
	 * 判断是否锁定
	 */
	@Override
	public boolean getLocked()
	{
		if (this.getStatus()!=null && this.getStatus()==Constrains.PROJECT_STATUS_FROST)
		{
			return true;
		}
		else
		{
			return super.getLocked();
		}
	}

	public void setFrostReason(String frostReason) {
		this.frostReason = frostReason;
	}

	public String getFrostReason() {
		return frostReason;
	}
	
}
